<template>
    <div>
        <!-- 基本信息 -->
        <div class="bg-white ">
            <BaseHead>基本信息</BaseHead>
            <div class="p-[10px]">
                <el-descriptions title="" :column="2" border label-width="140">
                    <el-descriptions-item label-class-name="gdlable" label="奖励名称">{{
                    ruleForm.honorName
                }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="奖励级别">
                        <Feedback :id="ruleForm.honorLevel" :list="hjjbList">
                        </Feedback>
                    </el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="成果名称">{{
                    ruleForm.productName
                }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="所属单位">
                        <Feedback :id="ruleForm.unitId" :list="zcgsdwList" :mapping="['codeColumn', 'valueColumn']">
                        </Feedback>
                    </el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="申请日期">{{
                    dateFormatter3(ruleForm.applyDate)
                }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="学科名称">
                        <Feedback :id="ruleForm.subjectId" :list="kjxkflList" :mapping="['id', 'label']">
                        </Feedback>
                    </el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="完成单位">{{
                    ruleForm.completeUnit
                }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="成果形式">{{
                        ruleForm.productMode
                    }}</el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="申请书附件">
                        <div v-for="item in ruleForm.fileList" :key="item.id">{{ item.fileName
                            }}<el-link type="primary" style="margin-left: 8px;"
                                @click="downloadMet(item.id)">下载</el-link>
                        </div>
                    </el-descriptions-item>
                    <el-descriptions-item label-class-name="gdlable" label="备注">{{
                    ruleForm.note
                }}</el-descriptions-item>
                </el-descriptions>
            </div>
        </div>
        <!-- 完成人信息 -->
        <div class="bg-white mt-[10px]">
            <BaseHead>完成人信息 </BaseHead>
            <div class="p-[10px]">
                <el-table :data="tableData" border style="width: 100%">
                    <el-table-column align="center" type="index" label="署名顺序" width="80" />
                    <el-table-column align="center" prop="authorType" label="完成人类型">
                        <template #default="scope">
                            {{
                    scope.row.authorType == '1' ? '教师' : scope.row.authorType == '2' ? '学生' : '校外'
                }}</template>
                    </el-table-column>
                    <el-table-column align="center" prop="authorName" label="完成人姓名">

                    </el-table-column>
                    <el-table-column align="center" prop="address" label="性别">
                        <template #default="scope">
                            {{ scope.row.sexId == '1' ? '男' : scope.row.sexId == '0' ? '女' : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="eduLevelId" label="学历">
                        <template #default="scope">
                            <Feedback :id="scope.row.eduLevelId" :list="xlList">
                            </Feedback>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="authorUnit" label="工作单位">
                        <template #default="scope">
                            <span v-if="scope.row.authorType == 3">{{ scope.row.authorUnit }}</span>
                            <Feedback v-else :id="scope.row.authorUnitId" :list="sydwList"
                                :mapping="['codeColumn', 'valueColumn']">
                            </Feedback>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="titleId" label="职称">
                        <template #default="scope">
                            <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                                :render-after-expand="false" disabled />
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="workRatio" label="贡献率（%）">
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import useCategoryStore from "@/store/modules/category";

const props = defineProps({
    id: String,
})

const categoryStore = useCategoryStore();
const { hjztList, zcgsdwList, hjjbList, kjxkflList, xlList, zcList, sydwList } = storeToRefs(categoryStore); // 解构状态
const { gethjztList, getzcgsdwList, gethjjbList, getkjxkflList, getxlList, getzcList, getsydwList } = categoryStore; // 解构方法



const ruleForm = reactive({
    name: '',
    applyInfoId: '',
    honorName: '',
    honorLevel: '',
    productName: '',
    unitId: '',
    subjectId: '',
    completeUnit: '',
    productMode: '',
    note: '',
});
const tableData = reactive([
]);

const formatHonorLevelId = (cellValue) => {
    if (props.hjjbList.length && cellValue) {
        return props.hjjbList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}
const formatUnitId = (cellValue) => {
    if (props.zcgsdwList.length && cellValue) {
        return props.zcgsdwList.find(item => item.codeColumn == cellValue).valueColumn
    } else {
        return ''
    }


}


const formateduLevelId = (cellValue) => {
    if (props.xlList.length && cellValue) {
        return props.xlList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}

const getRuleForm = (i, j) => {
    if (!hjztList.value.length) {
        gethjztList()
    }
    if (!zcgsdwList.value.length) {
        getzcgsdwList()
    }
    if (!hjjbList.value.length) {
        gethjjbList()
    }
    if (!kjxkflList.value.length) {
        getkjxkflList()
    }
    if (!xlList.value.length) {
        getxlList()
    }
    if (!zcList.value.length) {
        getzcList()
    }
    if (!sydwList.value.length) {
        getsydwList()
    }

    if (i.honorApplyBookMemberVOs && i.honorApplyBookMemberVOs.length > 0) {
        tableData.length = 0; // 清空数组
        tableData.push(...i.honorApplyBookMemberVOs); // 添加新元素

    }
    for (const key in i) {
        ruleForm[key] = i[key];
    }
}
const { proxy } = getCurrentInstance();
const downloadMet = (i) => {
    proxy.$download.common(i)
}
defineExpose({
    getRuleForm
})
</script>
<style lang="scss">
.gdlable {
    width: 140px;
}
</style>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");

:deep(.el-select--default) {


    .el-select__wrapper.is-disabled {
        background-color: #fff;
        box-shadow: 0 0 0 0px var(--el-select-disabled-border) inset;
        color: #606266;
        cursor: not-allowed;

        .el-select__selected-item {
            color: #606266;
        }
    }

    .el-select__suffix {
        display: none;
    }
}
</style>
